﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;

/// <summary>
/// Various small functions are used here to keep the SPA more clean.
/// </summary>
public class WbVarious
{
	public static string FormatDN(string distinguishedname) 
    {
        string[] outmp = distinguishedname.Split(',');
        Array.Reverse(outmp);

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < outmp.Length; i++)
        {
            sb.Append(outmp[i]).Append(',');
        }

        string ouname = sb.ToString().Substring(0, sb.ToString().Length - 1);
        return ouname;    
    }       

    public static string RmInvalidChrs(string name)
    {
        name.Trim();        
        string[] ichrs = new string[] {
            "&", "\'", "*", "@", "\\", "{",
            "}", "^",  ":", "$", "!", "#",
            ">", "<",  ")", "(", "%", ".",
            "?", "\"", "/","~", "_", "|"
        };        
        foreach (string chr in ichrs)
        {
            name = name.Replace(chr,"");
        }
        return name;
    }

    public static string RmInvalidChrsV2(string name)
    {
        name.Trim();
        string[] ichrs = new string[] {
            "&", "\'", "*", "@", "\\", "{",
            "}", "^",  ":", "$", "!", "#",
            ">", "<",  ")", "(", "%", ".",
            "?", "\"", "/","~", "|"
        };

        foreach (string chr in ichrs)
        {
            name = name.Replace(chr, "");
        }

        return name;
    }
}

